﻿#region Utilities
using System;
using System.Drawing;
using System.Windows.Forms;
using CommonUtilities.Enums;
using CommonUtilities.Extensions;
using CommonUtilities.Properties;
#endregion

namespace CommonUtilities.Controls
{
    public partial class CUtil_DirectionButtons : UserControl
    {
        #region Declarations
        private const int BUTTON_HEIGHT = 23;
        private readonly Size HBUTTON_SIZE = new Size(78, BUTTON_HEIGHT);
        private readonly Size VBUTTONSIZE = new Size(53, BUTTON_HEIGHT);
        private readonly Size SQUARESIZE = new Size(BUTTON_HEIGHT, BUTTON_HEIGHT);

        const string DISPLAY_LEFT = "< &Prev";
        const string DISPLAY_RIGHT = "&Next >";
        const string DISPLAY_TOP = "&Up";
        const string DISPLAY_BOTTOM = "&Down";
        const string DISPLAY_DEFAULT = "HVButton";

        public new event EventHandler Click;
        #endregion

        #region Properties
        public string ButtonText
        {
            get { return btnHVButton.Text; }
        }

        public Size ButtonSize
        {
            get { return btnHVButton.Size; }
        }

        private bool miniMode;
        public bool MiniMode
        {
            get { return miniMode; }
            set { miniMode = value; UpdateButtonDesign(); }
        }

        private eButtonDirection buttonDirection;
        public eButtonDirection ButtonDirection
        {
            get { return buttonDirection; }
            set { buttonDirection = value; UpdateButtonDesign(); }
        }
        #endregion

        #region Constructors
        public CUtil_DirectionButtons()
        {
            InitializeComponent();

            ButtonDirection = eButtonDirection.Default;
            MiniMode = false;
        }
        #endregion

        #region Methods
        private void UpdateButtonDesign()
        {
            switch (buttonDirection)
            {
                case eButtonDirection.Left:
                    UpdateButtonSize(HBUTTON_SIZE);
                    btnHVButton.Image = Resources.Direction_Left;
                    btnHVButton.ImageAlign = ContentAlignment.MiddleLeft;
                    btnHVButton.Text = DISPLAY_LEFT;
                    break;

                case eButtonDirection.Right:
                    UpdateButtonSize(HBUTTON_SIZE);
                    btnHVButton.Image = Resources.Direction_Right;
                    btnHVButton.ImageAlign = ContentAlignment.MiddleRight;
                    btnHVButton.Text = DISPLAY_RIGHT;
                    break;

                case eButtonDirection.Top:
                    UpdateButtonSize(VBUTTONSIZE);
                    btnHVButton.Image = Resources.Direction_Up;
                    btnHVButton.ImageAlign = ContentAlignment.TopCenter;
                    btnHVButton.Text = DISPLAY_TOP;
                    break;

                case eButtonDirection.Bottom:
                    UpdateButtonSize(VBUTTONSIZE);
                    btnHVButton.Image = Resources.Direction_Down;
                    btnHVButton.ImageAlign = ContentAlignment.BottomCenter;
                    btnHVButton.Text = DISPLAY_BOTTOM;
                    break;

                case eButtonDirection.Default:
                default:
                    UpdateButtonSize(HBUTTON_SIZE);
                    btnHVButton.Image = null;
                    btnHVButton.Text = DISPLAY_DEFAULT;
                    break;
            }
        }

        private void UpdateButtonSize(Size value)
        {
            btnHVButton.MaximumSize = btnHVButton.MinimumSize
                = this.MaximumSize = this.MinimumSize
                = this.Size = btnHVButton.Size = (miniMode ? SQUARESIZE : value);
        }
        #endregion

        #region Events
        private void btnHVButton_Click(object sender, EventArgs e)
        {
            if (!this.Click.IsNull()) this.Click(this, e);
        }
        #endregion
    }
}
